home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / sgf2mi13.taz / sgf2mi13 / sgf2misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-27  |  5.0 KB  |  201 lines

  1. /* #[info:            */
  2. /************************************************************************
  3.  *                                    *
  4.  *         ####  ####  #####        #    # ###  ####   ###        *
  5.  *        #     #      #      ###   ##  ##  #  #      #           *
  6.  *        #     #      #     #   #  # ## #  #  #     #            *
  7.  *         ###  #  ##  ###      #   #    #  #   ###  #            *
  8.  *            # #    # #       #    #    #  #      # #            *
  9.  *            # #    # #      #     #    #  #      #  #           *
  10.  *        ####   ####  #     ###### #    # ### ####    ###        *
  11.  *                                    *
  12.  *                Jan van der Steen                *
  13.  *                                    *
  14.  *          Centre for Mathematics and Computer Science        *
  15.  *              Amsterdam, the Netherlands            *
  16.  *                                    *
  17.  *----------------------------------------------------------------------*
  18.  * File    : sgf2misc.c                         *
  19.  * Purpose : Read and convert a Smart Go Format file            *
  20.  * Version : 1.12                         *
  21.  * Modified: 2/14/93 13:39:07                        *
  22.  * Author  : Jan van der Steen (jansteen@cwi.nl)             *
  23.  ************************************************************************/
  24. /* #]info:            */ 
  25. /* #[README:            */
  26.  
  27. /*
  28.  * A Mickey-Mouse Smart Go Format to LaTeX/SGF converter. It
  29.  * is developed as a quick hack to convert the Otake-Kobayashi
  30.  * Meijin game to a printable and rather portable document.
  31.  * The converter doesn't have much knowledge about SGF format yet.
  32.  * It's typically based on the SGF files as produced by IGS:
  33.  *
  34.  *    (
  35.  *    ;
  36.  *    EVent[A game played on the Internet Go Server]
  37.  *    USer[Brought to you by the IGS program]
  38.  *    PlayerBlack[kobayashi]
  39.  *    BlackRanking[NR]
  40.  *    PlayerWhite[otake]
  41.  *    WhiteRanking[NR]
  42.  *    DaTe[1992-09-15]
  43.  *    GaMe[1]
  44.  *    VieW[]
  45.  *    SiZe[19]
  46.  *    GameName[(IGS) otake(W) vs kobayashi(B)]
  47.  *    PlaCe[IGS:  Albuquerque, NM, USA 129.24.14.70 6969]
  48.  *    REsult[B+resign]
  49.  *    KoMi[0.000000]
  50.  *    BlacktimeLeft[0]
  51.  *    WhitetimeLeft[0]
  52.  *    ;
  53.  *    B[pd]
  54.  *    ;
  55.  *    W[dd]
  56.  *    C[
  57.  *     zhuge NR: okay, L3.
  58.  *     jjs NR: yeah, but i have oddive hour at 2pm
  59.  *    ]
  60.  *    ;
  61.  *    )
  62.  *
  63.  * Some general characteristics of the sgf2TeX convertion
  64.  * ------------------------------------------------------
  65.  * 1. It only recognise moves and kibitz comments.
  66.  * 2. It exchanges move and kibitz.
  67.  *    They are written in the sgf file in the wrong order
  68.  *    (i.e. first move then kibitz).
  69.  * 3. Merge moves without kibitz in one diagram.
  70.  * 4. Generate one kibitz label for consequetive kibitzes.
  71.  */
  72.  
  73. /* #]README:            */ 
  74. /* #[include:            */
  75.  
  76. #include <stdio.h>
  77. #include <stdlib.h>
  78. #include <string.h>
  79. #include "gogame.h"
  80. #include "sgfread.h"
  81. #include "game2tex.h"
  82. #include "game2eps.h"
  83. #include "game2sgf.h"
  84. #include "tools.h"
  85. #include "sysdep.h"
  86.  
  87. /* #]include:            */ 
  88. /* #[global:            */
  89.  
  90. int        optind  = 1;        /* index into argv vector    */
  91. int        caching = 0;        /* Caching mode            */
  92. int        textout    = 1;        /* Emit the text        */
  93. int        statout    = 0;        /* Emit the kibitz stats    */
  94. int        coords    = 1;        /* Print coordinates        */
  95. char *        program = "sgf2misc";    /* Program name            */
  96. int        verbose = 0;        /* Verbose mode            */
  97. EPSFINFO    epsf;            /* The eps filename/directory    */
  98. /*
  99.  * The next variable decides how to solve the Go diagram issue:
  100.  *
  101.  *    DEVICE_EPS   Diagrams are handled by epsf PostScript inclusion
  102.  *    DEVICE_TEX   Diagrams are handled by a special TeX Go font
  103.  */
  104. int        prn_dev = DEVICE_EPS;    /* DEVICE_{EPS,TEX}        */
  105.  
  106. /*
  107.  * The next variables allow the user to specify an output list
  108.  * of figures/diagrams
  109.  */
  110. int        figlist[MAXNUM];    /* Figure  list            */
  111. int        dialist[MAXNUM];    /* Diagram list            */
  112. int        user_figs = 0;        /* Users fig list?        */
  113. int        user_dias = 0;        /* Users dia list?        */
  114.  
  115. /* #]global:            */ 
  116. /* #[prototype:            */
  117.  
  118. #ifdef __STDC__
  119. #    define    PROTO(s) s
  120. #else
  121. #    define    PROTO(s) ()
  122. #endif
  123.  
  124. void        main        PROTO((int argc, char **argv));
  125. static char *    epsf_filename    PROTO((char *fullpathname));
  126.  
  127. #undef PROTO
  128.  
  129. /* #]prototype:            */ 
  130.  
  131. /* #[main:            */
  132.  
  133. void
  134. main(argc, argv)
  135. int    argc;
  136. char **argv;
  137. {
  138.     GOGAME *gogame = (GOGAME *) 0;    /* The complete game    */
  139.     FILE   *fp     = stdin;        /* The read channel    */
  140.  
  141. #if defined(ATARI)
  142.     argv[0] = program;
  143. #else
  144.     program = argv[0];
  145. #endif
  146.     getoptions(argc, argv);
  147.  
  148.     /*
  149.      * Process the Smart Go Format file
  150.      */
  151.     if (optind < argc) {
  152.     if ((fp = fopen(argv[optind], "r")) == (FILE *) 0) {
  153.         fprintf(stderr, "Can't open \"%s\"\n", argv[optind]);
  154.         exit(1);
  155.     }
  156.     epsf.eps_name = epsf_filename(argv[optind]);
  157.     } else
  158.     epsf.eps_name = "stdin";
  159.  
  160.     if ((gogame = sgf_read(fp)) != (GOGAME *) 0) {
  161.     if (user_figs)    list2tex(gogame);
  162.     else        game2tex(gogame);
  163.     game_free (gogame);
  164.     }
  165.     exit(0);
  166. }
  167.  
  168. /* #]main:            */ 
  169. /* #[epsf_filename:        */ 
  170.  
  171. static char *
  172. epsf_filename(fullpathname)
  173. /*
  174.  * Look for suffix and delete it (detructive on source!)
  175.  * Next, return the basename of the file.
  176.  */
  177. char *fullpathname;
  178. {
  179.     char *s = fullpathname;
  180.  
  181.     /*
  182.      * First delete the suffix
  183.      */
  184.     while (*s) s++;
  185.     while (s > fullpathname && *s != PATHSEP && *s != '.') s--;
  186.     /*
  187.      * We never want to remove the path seperator
  188.      */
  189.     if (*s != PATHSEP) *s = 0;
  190.  
  191.     /*
  192.      * Next, return the basename
  193.      */
  194.     while (s > fullpathname && *s != PATHSEP) s--;
  195.     if (*s == PATHSEP) s++;
  196.  
  197.     return s;
  198. }
  199.  
  200. /* #]epsf_filename:        */ 
  201.